package com.song.controller.admin;


import com.song.entity.Lend;
import com.song.result.Result;
import com.song.service.LendService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author Song
 * @since 2025-01-03
 */
@RestController
@RequestMapping("/admin/core/lend")
public class AdminLendController {

    @Autowired
    private LendService lendService;

    //http://localhost/admin/core/lend/list
    @ApiOperation("显示所有标的信息")
    @GetMapping("/list")
    public Result list(){
        List<Lend> lendList= lendService.selectList();
        return  Result.ok().data("list",lendList);
    }

    //http://localhost/admin/core/lend/show/1
    @ApiOperation("查看单个标的信息")
    @GetMapping("/show/{id}")
    public Result show(@ApiParam(value = "标的的ID",required = true) @PathVariable Long id){
        Map<String, Object> map = lendService.selectLendById(id);
        return  Result.ok().data("lendDetail",map);
    }


    //url: `/admin/core/lend/makeLoan/${id}`
    @ApiOperation("放款")
    @GetMapping("/makeLoan/{id}")
    public Result makeLoan(@ApiParam(value = "标的的ID",required = true) @PathVariable Long id){
        lendService.makeLoan(id);
        return  Result.ok().message("放款成功!");
    }


}

